import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Controller;

import net.sshiffon.ConnectionSetting;
import groovy.beans.Bindable

class ConnectionTabModel {
		@Bindable boolean dirty
		@Bindable boolean readyToConnect
		@Bindable boolean readyToSave
		@Bindable boolean readyToAddTunnel
		@Bindable boolean connected
		@Bindable boolean empty=true
		@Bindable boolean  connectionSelected
		def connectedGroup
		@Bindable def netInterfaces= []
		@Bindable ConnectionSetting currentSetting= new ConnectionSetting()
		@Bindable ConnectionSetting settingFromPicker= new ConnectionSetting()
		@Bindable anyTunnelsSelected = false
		@Bindable tunnels= []
        
		def mvcId
		def tabs

        //state is populated on activation 
	    ConnectionTabState state

		def updateState()
		{
			if(connectedGroup)
			{
				updateState(connectedGroup.model.selectedCard)
			} else {
				updateState(null)
			}
		}
		
		def updateState(String viewName)
		{
			if(state)
			{
				logger.debug('updating global state')
				state.dirty = dirty
				state.connected = connected
				state.updateActiveView(viewName)
				if(connected)
				{
					connectedGroup.controller.setDisableOnly(viewName)
				} else {
			    	app.controllers.Sshiffon.setDisableOnly(viewName)
				}
			} else {
				logger.debug('No global state to update - inactive tab?')
			}
		}
}